package com.zcloud.eventstudydemo.llm;

import java.util.HashMap;
import java.util.Map;

/**
 * 文本分析结果实体类
 * 包含文本分析后的四个核心字段
 */
public class AnalysisResult {
    private String relatedEntity = "";      // 相关实体
    private String timeStart = "";          // 开始时间
    private String timeEnd = "";            // 结束时间
    private String eventContent = "";       // 事件详情

    /**
     * 默认构造函数
     */
    public AnalysisResult() {
    }

    /**
     * 带参数的构造函数
     *
     * @param relatedEntity 相关实体
     * @param timeStart     开始时间
     * @param timeEnd       结束时间
     * @param eventContent  事件详情
     */
    public AnalysisResult(String relatedEntity, String timeStart, String timeEnd, String eventContent) {
        this.relatedEntity = relatedEntity != null ? relatedEntity : "";
        this.timeStart = timeStart != null ? timeStart : "";
        this.timeEnd = timeEnd != null ? timeEnd : "";
        this.eventContent = eventContent != null ? eventContent : "";
    }

    // Getter 和 Setter 方法
    public String getRelatedEntity() {
        return relatedEntity;
    }

    public void setRelatedEntity(String relatedEntity) {
        this.relatedEntity = relatedEntity != null ? relatedEntity : "";
    }

    public String getTimeStart() {
        return timeStart;
    }

    public void setTimeStart(String timeStart) {
        this.timeStart = timeStart != null ? timeStart : "";
    }

    public String getTimeEnd() {
        return timeEnd;
    }

    public void setTimeEnd(String timeEnd) {
        this.timeEnd = timeEnd != null ? timeEnd : "";
    }

    public String getEventContent() {
        return eventContent;
    }

    public void setEventContent(String eventContent) {
        this.eventContent = eventContent != null ? eventContent : "";
    }

    /**
     * 转换为Map格式
     *
     * @return Map<String, Object> 包含所有字段的Map
     */
    public Map<String, Object> toMap() {
        Map<String, Object> map = new HashMap<>();
        map.put("related_entity", relatedEntity);
        map.put("time_start", timeStart);
        map.put("time_end", timeEnd);
        map.put("event_content", eventContent);
        return map;
    }

    /**
     * 字符串表示
     *
     * @return String 格式化的字符串
     */
    @Override
    public String toString() {
        StringBuilder output = new StringBuilder();
        output.append("==================================================\n");
        output.append("文本分析结果\n");
        output.append("==================================================\n");

        output.append("相关实体: ").append(relatedEntity.isEmpty() ? "[无]" : relatedEntity).append("\n");
        output.append("开始时间: ").append(timeStart.isEmpty() ? "[无]" : timeStart).append("\n");
        output.append("结束时间: ").append(timeEnd.isEmpty() ? "[无]" : timeEnd).append("\n");
        output.append("事件详情: ").append(eventContent.isEmpty() ? "[无]" : eventContent).append("\n");
        output.append("==================================================");

        return output.toString();
    }

    /**
     * 检查event_content字段是否有值
     *
     * @return boolean 如果有值返回true，否则返回false
     */
    public boolean hasEventContent() {
        return eventContent != null && !eventContent.trim().isEmpty();
    }
}
